package closure01

import java.text.SimpleDateFormat
import java.util.logging.SimpleFormatter

//协程
def itro(n,closure){
    1.upto(n){
        closure(it)
    }
}
total=0
//程序在itro和闭包中一直切换
itro(4) { total+=it; println("total-----${total}") }


//科里化闭包
def planByTime(closure){
    Date date=new Date()
    //使用科里化,避免date一直重复调用
    curry = closure.curry(new SimpleDateFormat("yyyy-MM-dd").format(date))
    curry "先做运动"
    curry "然后学习"
    curry "最后休息"
}
//需要两个参数
planByTime {date,plan->println "${date},${plan}"}

